"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const index = require("../panel/index.cjs");
require("../icons/index.cjs");
require("./resource-filter-panel.vue.cjs");
const antDesignVue = require("ant-design-vue");
const settingIcon = require("../icons/setting-icon.vue.cjs");
const resourceFilterPanel_vue_vue_type_script_setup_true_lang = require("./resource-filter-panel.vue2.cjs");
const caretDownIcon = require("../icons/caret-down-icon.vue.cjs");
const caretUpIcon = require("../icons/caret-up-icon.vue.cjs");
const _hoisted_1 = { class: "me-resource-panel" };
const _hoisted_2 = { class: "me-resource-panel-header" };
const _hoisted_3 = { class: "me-resource-panel-content" };
const _hoisted_4 = {
  key: 0,
  class: "me-resource-panel-list"
};
const _hoisted_5 = ["onClick"];
const _hoisted_6 = { class: "me-resource-panel-list-item-text" };
const _hoisted_7 = { class: "me-resource-panel-list-header" };
const _hoisted_8 = { class: "me-resource-panel-list-header-text" };
const _hoisted_9 = ["onClick"];
const _hoisted_10 = { class: "me-resource-panel-list-item-text" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "me-resource-panel"
  },
  __name: "resource-panel",
  props: {
    title: { default: "资源图层" },
    layerList: { default() {
      return [];
    } },
    simple: { type: Boolean, default: false },
    header: { type: Boolean, default: true },
    columns: { default: 3 }
  },
  emits: ["filter", "add", "delete", "reset"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const currentLayerId = vue.ref("");
    const filterList = vue.ref([[]]);
    const layerList = vue.ref(props.layerList || []);
    const showFilter = vue.ref(false);
    let initialLayerList = JSON.parse(JSON.stringify(props.layerList)) || [];
    const findLayerById = (layerId, list) => {
      let result = null;
      const traverse = (layerList2) => {
        for (let i = 0; i < layerList2.length; i++) {
          const layer = layerList2[i];
          if (layer.layerId === layerId) {
            result = layer;
            break;
          }
          if (layer.children && layer.children.length > 0) {
            traverse(layer.children);
          }
        }
      };
      traverse(list);
      return result;
    };
    const getSelectedLayerIdList = (layerList2) => {
      const list = [];
      const traverse = (layerList3) => {
        layerList3.map((layer) => {
          if (layer.selected) {
            list.push(layer.layerId);
          }
          ;
          if (layer.children && layer.children.length > 0) {
            traverse(layer.children);
          }
        });
      };
      traverse(layerList2);
      return list;
    };
    const resetLayerList = (list) => {
      layerList.value = JSON.parse(JSON.stringify(list));
      const traverse = (list2) => {
        list2.map((layer) => {
          layer.selected = false;
          if (layer.layerId && selectedLayerIds.value.includes(layer.layerId)) {
            layer.selected = true;
          }
          ;
          if (layer.children && layer.children.length > 0) {
            traverse(layer.children);
          }
        });
      };
      traverse(layerList.value);
    };
    const resetSelectedLayerIds = (list) => {
      const currentSelectedIds = [];
      const traverse = (list2) => {
        list2.map((layer) => {
          if (layer.selected) {
            layer.layerId && currentSelectedIds.push(layer.layerId);
          }
          if (layer.children && layer.children.length > 0) {
            traverse(layer.children);
          }
        });
      };
      traverse(list);
      selectedLayerIds.value = currentSelectedIds;
    };
    const selectedLayerIds = vue.ref(getSelectedLayerIdList(props.layerList) || []);
    vue.watch(() => props.layerList, () => {
      initialLayerList = JSON.parse(JSON.stringify(props.layerList));
      resetLayerList(props.layerList);
      resetSelectedLayerIds(layerList.value);
    }, { immediate: true });
    const clickArrow = (layer) => {
      if (layer.selected) {
        if (layer.layerId !== currentLayerId.value) {
          currentLayerId.value = "";
          showFilter.value = true;
        }
        if (!currentLayerId.value) {
          currentLayerId.value = layer.layerId;
          filterList.value = parseFilterList(layer.filterList);
        } else {
          currentLayerId.value = "";
        }
      }
    };
    const parseFilterList = (filterList2 = []) => {
      const filter = {};
      filterList2.map((item) => {
        filter[item.type] = filter[item.type] || (filter[item.type] = []);
        filter[item.type].push(item);
      });
      return Object.values(filter);
    };
    const visibleChange = (visible) => {
      if (!visible) {
        currentLayerId.value = "";
      }
    };
    const onFilter = (data, layer) => {
      emits("filter", layer, data);
    };
    const onClick = (layer) => {
      layer.selected = !layer.selected;
      setTimeout(() => {
        if (layer.selected) {
          selectedLayerIds.value.push(layer.layerId);
          emits("add", layer);
        } else {
          emits("delete", layer);
          selectedLayerIds.value = selectedLayerIds.value.filter((id) => id !== layer.layerId);
        }
      });
    };
    const reset = () => {
      layerList.value = JSON.parse(JSON.stringify(initialLayerList));
      emits("reset");
    };
    const resetFilter = (layer) => {
      var _a;
      const initialLayer = findLayerById(layer.layerId, initialLayerList);
      if (initialLayer) {
        const cloneLayer = initialLayer;
        (_a = cloneLayer.filterList) == null ? void 0 : _a.map((item) => {
          var _a2;
          (_a2 = layer.filterList) == null ? void 0 : _a2.map((i) => {
            if (item.name === i.name) {
              i.selected = item.selected;
            }
          });
        });
        filterList.value = parseFilterList(cloneLayer.filterList);
      }
    };
    const getSelectedIds = () => {
      return selectedLayerIds.value;
    };
    __expose({
      // 重置当前资源图层对象的筛选条件
      resetFilter,
      // 重置整个资源图层
      reset,
      // 获取选中的图层id集合
      getSelectedIds
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.createVNode(vue.unref(index.Panel), null, {
          default: vue.withCtx(() => [
            _ctx.header ? (vue.openBlock(), vue.createBlock(vue.unref(index.PanelTitle), {
              key: 0,
              title: _ctx.title
            }, {
              content: vue.withCtx(() => [
                vue.createElementVNode("div", _hoisted_2, [
                  vue.renderSlot(_ctx.$slots, "title", {}, () => [
                    vue.createVNode(vue.unref(settingIcon.default), { class: "me-resource-panel-setting-icon" })
                  ])
                ])
              ]),
              _: 3
            }, 8, ["title"])) : vue.createCommentVNode("", true),
            vue.createVNode(vue.unref(index.PanelContent), null, {
              default: vue.withCtx(() => [
                vue.createElementVNode("div", _hoisted_3, [
                  _ctx.simple ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
                    vue.createElementVNode("div", {
                      style: vue.normalizeStyle({ gridTemplateColumns: `repeat(${_ctx.columns} , calc(${100 / _ctx.columns + "%"} - ${(_ctx.columns - 1) * 10 / _ctx.columns}px))` }),
                      class: "me-resource-panel-list-content"
                    }, [
                      (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(layerList.value, (layer, index2) => {
                        return vue.openBlock(), vue.createElementBlock("div", {
                          onClick: ($event) => onClick(layer),
                          key: index2,
                          class: vue.normalizeClass([{ selected: layer.selected }, "me-resource-panel-list-item"])
                        }, [
                          vue.createElementVNode("span", _hoisted_6, vue.toDisplayString(layer.title), 1),
                          selectedLayerIds.value.includes(layer.layerId) ? (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Popover), {
                            key: 0,
                            trigger: "click",
                            onVisibleChange: visibleChange,
                            placement: "right"
                          }, {
                            content: vue.withCtx(() => [
                              vue.createVNode(resourceFilterPanel_vue_vue_type_script_setup_true_lang.default, {
                                onClick: onFilter,
                                layer,
                                "filter-list": filterList.value
                              }, null, 8, ["layer", "filter-list"])
                            ]),
                            default: vue.withCtx(() => [
                              layer.selected && currentLayerId.value !== layer.layerId ? (vue.openBlock(), vue.createBlock(vue.unref(caretDownIcon.default), {
                                key: 0,
                                onClick: vue.withModifiers(($event) => clickArrow(layer), ["stop"]),
                                class: "me-resource-panel-list-icon"
                              }, null, 8, ["onClick"])) : vue.createCommentVNode("", true),
                              layer.selected && currentLayerId.value === layer.layerId ? (vue.openBlock(), vue.createBlock(vue.unref(caretUpIcon.default), {
                                key: 1,
                                onClick: vue.withModifiers(($event) => clickArrow(layer), ["stop"]),
                                class: "me-resource-panel-list-icon"
                              }, null, 8, ["onClick"])) : vue.createCommentVNode("", true)
                            ]),
                            _: 2
                          }, 1024)) : vue.createCommentVNode("", true)
                        ], 10, _hoisted_5);
                      }), 128))
                    ], 4)
                  ])) : (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 1 }, vue.renderList(layerList.value, (item, index2) => {
                    return vue.openBlock(), vue.createElementBlock("div", {
                      class: "me-resource-panel-list",
                      key: index2
                    }, [
                      vue.createElementVNode("div", _hoisted_7, [
                        vue.createElementVNode("span", _hoisted_8, vue.toDisplayString(item.title), 1)
                      ]),
                      vue.createElementVNode("div", {
                        style: vue.normalizeStyle({ gridTemplateColumns: `repeat(${_ctx.columns} , calc(${100 / _ctx.columns + "%"} - ${(_ctx.columns - 1) * 10 / _ctx.columns}px))` }),
                        class: "me-resource-panel-list-content"
                      }, [
                        (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(item.children, (layer, index22) => {
                          return vue.openBlock(), vue.createElementBlock("div", {
                            onClick: ($event) => onClick(layer),
                            class: vue.normalizeClass([{ selected: layer.selected }, "me-resource-panel-list-item"]),
                            key: index22
                          }, [
                            vue.createElementVNode("span", _hoisted_10, vue.toDisplayString(layer.title), 1),
                            selectedLayerIds.value.includes(layer.layerId) ? (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Popover), {
                              key: 0,
                              trigger: "click",
                              onVisibleChange: visibleChange,
                              placement: "right"
                            }, {
                              content: vue.withCtx(() => [
                                vue.createVNode(resourceFilterPanel_vue_vue_type_script_setup_true_lang.default, {
                                  onClick: onFilter,
                                  layer,
                                  "filter-list": filterList.value
                                }, null, 8, ["layer", "filter-list"])
                              ]),
                              default: vue.withCtx(() => [
                                layer.selected && currentLayerId.value !== layer.layerId ? (vue.openBlock(), vue.createBlock(vue.unref(caretDownIcon.default), {
                                  key: 0,
                                  onClick: vue.withModifiers(($event) => clickArrow(layer), ["stop"]),
                                  class: "me-resource-panel-list-icon"
                                }, null, 8, ["onClick"])) : vue.createCommentVNode("", true),
                                layer.selected && currentLayerId.value === layer.layerId ? (vue.openBlock(), vue.createBlock(vue.unref(caretUpIcon.default), {
                                  key: 1,
                                  onClick: vue.withModifiers(($event) => clickArrow(layer), ["stop"]),
                                  class: "me-resource-panel-list-icon"
                                }, null, 8, ["onClick"])) : vue.createCommentVNode("", true)
                              ]),
                              _: 2
                            }, 1024)) : vue.createCommentVNode("", true)
                          ], 10, _hoisted_9);
                        }), 128))
                      ], 4)
                    ]);
                  }), 128))
                ])
              ]),
              _: 1
            })
          ]),
          _: 3
        })
      ]);
    };
  }
});
exports.default = _sfc_main;
//# sourceMappingURL=resource-panel.vue2.cjs.map
